#include"CommandServer.hpp"
#include"Logger.hpp"
#include"Command.hpp"
#include<memory>

void Usage(std::string proc)
{
    std::cerr << "Usage " << proc <<" serverport" << std::endl;
}

// std::string CommandExec(const std::string& commandstr)
// {
//     ;
// }

//./server serverport
int main(int argc , char* argv[])
{   
    if(argc != 2)
    {
        Usage(argv[0]);
        return 0;
    }

    EnableConsoleLogStrategy();
    uint16_t port = std::stoi(argv[1]);

    //将处理命令面向对象化 -> 使用类封装
    //创建对象
    Command cmdobj;
    std::unique_ptr<CommandServer> tsvr = std::make_unique<CommandServer>(
        [&cmdobj](const std::string& cmd)->std::string{
            return cmdobj.Exec(cmd);
        }
        ,port);

    tsvr->Init();
    tsvr->Start();

    return 0;
}